<?php

namespace App\Admin\Actions\Area;

use App\Miya\Models\Area;
use Encore\Admin\Actions\Action;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ClearArea extends Action
{
    protected $selector = '.clear-area';

    public function handle(Request $request)
    {
        Area::where('id', '>', 0)->delete();
        //重置自增id
        $statement = "ALTER TABLE `miya3_areas` AUTO_INCREMENT = 1;";
        DB::unprepared($statement);

        return $this->response()->success('清除地区成功!')->refresh();
    }

    public function html()
    {
        return <<<HTML
        <a class="btn btn-sm btn-danger clear-area">清除地区</a>
HTML;
    }
}
